import sys
import numpy as np
import pandas as pd
import plotly.graph_objects as go
from tqdm import tqdm
from datatable import dt, f, by
from itables import init_notebook_mode
init_notebook_mode(all_interactive=True)
from plotly import express as px, io as pio
pd.options.plotting.backend = 'plotly'
pio.renderers.default = 'plotly_mimetype+notebook_connected'
from utils import get_path, data_load
sys.path.insert(0, '../')
from secret import API_KEYNetwork Geoplot
Fontes de Dados
Procedimentos
Colunas
cols_proc = [
'bienio', 'parto_normal', 'criticidade',
'origem_latitude', 'origem_longitude',
'destino_latitude', 'destino_longitude',
'count',
]Carregando tabela
path_proc = get_path('GESTANTES', f'procs.csv.gzip')
df_proc = df_proc_bienio = pd.read_csv(path_proc)
df_proc = df_proc[cols_proc]
df_proc = df_proc[df_proc['criticidade'] > 0]
df_proc = df_proc.drop('criticidade', axis=1)
df_proc = df_proc.groupby(
by=list(df_proc.columns[:-1]),
as_index=False
).sum()
df_proc| bienio | parto_normal | origem_latitude | origem_longitude | destino_latitude | destino_longitude | count |
|---|---|---|---|---|---|---|
| Loading... (need help?) |
Resultados
df_proc = df_proc.sort_values(by='count', ascending=False)
df_proc| bienio | parto_normal | origem_latitude | origem_longitude | destino_latitude | destino_longitude | count | |
|---|---|---|---|---|---|---|---|
| Loading... (need help?) |
fig = go.Figure()
# fig.add_trace(go.Scattergeo(
# locationmode = 'BRA-states',
# lon = df_airports['long'],
# lat = df_airports['lat'],
# hoverinfo = 'text',
# text = df_airports['airport'],
# mode = 'markers',
# marker = dict(
# size = 2,
# color = 'rgb(255, 0, 0)',
# line = dict(
# width = 3,
# color = 'rgba(68, 68, 68, 0)'
# )
# )))
flight_paths = []
for i in tqdm(range(len(df_proc))):
fig.add_trace(
go.Scattergeo(
# locationmode = 'BRA-states',
lon = [df_proc['origem_longitude'][i], df_proc['destino_longitude'][i]],
lat = [df_proc['origem_latitude'][i], df_proc['destino_latitude'][i]],
mode = 'lines',
line = dict(width = 1,color = 'red'),
opacity = float(df_proc['count'][i]) / float(df_proc['count'].max()),
)
)
fig.update_layout(
title_text = 'Brasil',
showlegend = False,
geo = dict(
scope = 'south america',
projection_type = 'azimuthal equal area',
showland = True,
landcolor = 'rgb(243, 243, 243)',
countrycolor = 'rgb(204, 204, 204)',
),
)
fig.show()100%|██████████| 88113/88113 [01:28<00:00, 996.77it/s]